package app.fugema.shop.main.home.adapter;

import android.view.View;

import com.base.common.app.LoginUtils;
import com.base.common.utils.UIUtils;
import com.base.common.view.adapter.connector.BaseItemMultiType;
import com.base.common.view.adapter.connector.BaseItemTypeInterface;
import com.base.common.view.adapter.connector.BaseViewHolder;
import com.base.common.view.widget.imageView.ImageLoaderUtils;

import app.fugema.shop.BuildConfig;
import app.fugema.shop.R;
import app.fugema.shop.databinding.HomeItemImgLink21ViewBinding;
import app.fugema.shop.main.home.model.HomeData;
import app.fugema.shop.main.setting.view.WebActivity;

public class HomeLink21MultiType extends BaseItemMultiType<HomeData.LModulesBean, HomeItemImgLink21ViewBinding>
{

    @Override
    public int getLayoutId()
    {
        return R.layout.home_item_img_link21_view;
    }

    @Override
    public int getItemViewType()
    {
        return BaseItemTypeInterface.TYPE_CHILD_TWO;
    }

    @Override
    public boolean isFullSpanType()
    {
        return true;
    }

    @Override
    public void onBindViewHolder(HomeItemImgLink21ViewBinding binding, int position, BaseViewHolder viewHolder, HomeData.LModulesBean bean)
    {
        super.onBindViewHolder(binding, position, viewHolder, bean);
        for( int i =0 ; i < bean.getContent().getDataset().size();i++  )
        {
            switch ( i )
            {
                case 0:
                    ImageLoaderUtils.loadImage(binding.givLink21Img1 , bean.getContent().getDataset().get(i).getPic() );
                    break;
                case 1:
                    ImageLoaderUtils.loadImage(binding.givLink21Img2 , bean.getContent().getDataset().get(i).getPic() );
                    break;
                case 2:
                    ImageLoaderUtils.loadImage(binding.givLink21Img3 , bean.getContent().getDataset().get(i).getPic() );
                    break;
                case 3:
                    ImageLoaderUtils.loadImage(binding.givLink21Img4 , bean.getContent().getDataset().get(i).getPic() );
                    break;
                case 4:
                    ImageLoaderUtils.loadImage(binding.givLink21Img5 , bean.getContent().getDataset().get(i).getPic() );
                    break;
                case 5:
                    ImageLoaderUtils.loadImage(binding.givLink21Img6 , bean.getContent().getDataset().get(i).getPic() );
                    break;
                case 6:
                    ImageLoaderUtils.loadImage(binding.givLink21Img7 , bean.getContent().getDataset().get(i).getPic() );
                    break;
            }
        }
    }

    @Override
    public void onItemClick(View view, int onclickType, int position, HomeData.LModulesBean bean)
    {
        super.onItemClick(view, onclickType, position, bean);

        int index = 0;
        switch ( view.getId()  )
        {
            case R.id.giv_link21_img1:
                index = 0;
                break;
            case R.id.giv_link21_img2:
                index = 1;
                break;
            case R.id.giv_link21_img3:
                index = 2;
                break;
            case R.id.giv_link21_img4:
                index = 3;
                break;
            case R.id.giv_link21_img5:
                index = 4;
                break;
            case R.id.giv_link21_img6:
                index = 5;
                break;
            case R.id.giv_link21_img7:
                index = 6;
                break;
        }

        HomeData.DatasetBean datasetBean = bean.getContent().getDataset().get(index);
        // 这里 需要判断 LinkType 的类型 判断 跳转的 位置
        if( !datasetBean.getLink().contains("#")  )
        {
            StringBuffer tokensb = new StringBuffer();
            if( UIUtils.isNotEmpty( LoginUtils.getToken() ) )
            {
                tokensb.append("?");
                tokensb.append("token");
                tokensb.append("=");
                tokensb.append(LoginUtils.getToken());
            }
            String tokenStr = UIUtils.isEmpty(tokensb.toString())?"":tokensb.toString();
            WebActivity.start(view.getContext() , BuildConfig.API_TEST + datasetBean.getLink().trim() + tokenStr );
        }
        /*
        switch ( datasetBean.getLinkType() )
        {
            case 8:
                break;
            default:
                break;
        }
        */
    }
}
